import type { NextConfig } from "next";
import path from "path";

const nextConfig: NextConfig = {
  // 根据环境变量设置basePath，开发环境不使用basePath
  basePath: process.env.NEXT_PUBLIC_ENV === 'development' ? '' : (process.env.NEXT_PUBLIC_BASE_PATH || '/wxpubpayweb'),
  // 启用静态导出
  output: "export",

  // 禁用图像优化，这在静态导出时是必需的
  images: {
    unoptimized: true,
  },

  webpack: (config) => {
    config.resolve.alias = {
      ...(config.resolve.alias || {}),
      "@": path.resolve(__dirname, "src"),
    };
    return config;
  },
  async rewrites() {
    return [
      {
        source: "/api/:path*",
        destination: `${process.env.NEXT_PUBLIC_API_BASE_URL}/wxpubpay/:path*`,
      },
    ];
  },
};


export default nextConfig;
